/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DataEditor.java
 *
 * Created on 2009-11-01, 02:44:11
 */
package mr.go.sgfilter.vis.app;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.NumberEditor;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.LineBorder;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.ELProperty;

/**
 *
 * @author Rzeźnik
 */
public class DataEditor extends javax.swing.JPanel {

    private final DataBean bean;

    /** Creates new form DataEditor */
    public DataEditor() {
        this(null);
    }

    public DataEditor(DataBean bean) {
        this.bean = bean;
        initComponents();
    }

    public DataBean getBean() {
        return bean;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new BindingGroup();

        padDataCheckBox = new JCheckBox();
        JLabel padLeftLabel = new JLabel();
        leftPadSizeSpinner = new JSpinner();
        padRightLabel = new JLabel();
        rightPadSizeSpinner = new JSpinner();
        ResourceMap resourceMap =
                Application.getInstance(mr.go.sgfilter.vis.app.Application.class).
                getContext().getResourceMap(DataEditor.class);
        setBorder(BorderFactory.createTitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), resourceMap.getString("DataEditor.border.title"))); // NOI18N
        setName("DataEditor"); // NOI18N
        setPreferredSize(new Dimension(470, 100));

        padDataCheckBox.setText(resourceMap.getString("padDataCheckBox.text")); // NOI18N
        padDataCheckBox.setName("padDataCheckBox"); // NOI18N

        Binding binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.padding}"), padDataCheckBox, BeanProperty.create("selected"));
        bindingGroup.addBinding(binding);

        padLeftLabel.setText(resourceMap.getString("padLeftLabel.text")); // NOI18N
        padLeftLabel.setName("padLeftLabel"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, padDataCheckBox, ELProperty.create("${selected}"), padLeftLabel, BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        leftPadSizeSpinner.setModel(new SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        leftPadSizeSpinner.setEditor(new NumberEditor(leftPadSizeSpinner, ""));
        leftPadSizeSpinner.setName("leftPadSizeSpinner"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.leftPadSize}"), leftPadSizeSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);
        binding = Bindings.createAutoBinding(UpdateStrategy.READ, padDataCheckBox, ELProperty.create("${selected}"), leftPadSizeSpinner, BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        padRightLabel.setText(resourceMap.getString("padRightLabel.text")); // NOI18N
        padRightLabel.setName("padRightLabel"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, padDataCheckBox, ELProperty.create("${selected}"), padRightLabel, BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        rightPadSizeSpinner.setModel(new SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        rightPadSizeSpinner.setEditor(new NumberEditor(rightPadSizeSpinner, ""));
        rightPadSizeSpinner.setName("rightPadSizeSpinner"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.rightPadSize}"), rightPadSizeSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);
        binding = Bindings.createAutoBinding(UpdateStrategy.READ, padDataCheckBox, ELProperty.create("${selected}"), rightPadSizeSpinner, BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(padDataCheckBox)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(padLeftLabel)
                        .addGap(18, 18, 18)
                        .addComponent(leftPadSizeSpinner, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(padRightLabel)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(rightPadSizeSpinner, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(112, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(padDataCheckBox)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(padLeftLabel)
                    .addComponent(leftPadSizeSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(padRightLabel)
                    .addComponent(rightPadSizeSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JSpinner leftPadSizeSpinner;
    private JCheckBox padDataCheckBox;
    private JLabel padRightLabel;
    private JSpinner rightPadSizeSpinner;
    private BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
